'use strict';
exports.main = async (event, context) => {
	//event为客户端上传的参数
	let openid=event.openid
	let state=event.state
	let tis=event.tis
	const db = uniCloud.database();
	const dbCmd=db.command;
	if(state==='正确')
	{
		let res=await db.collection('uni-id-users').where(dbCmd.and([{
						wx_openid: {
							"mp-weixin": openid
						}
					}, {
						nickname: dbCmd.exists(true)
					}])).update({
			correct_ti:dbCmd.push(tis)
		});
		return res
	}
	else if(state==='错误')
	{
		let res=await db.collection('uni-id-users').where(dbCmd.and([{
						wx_openid: {
							"mp-weixin": openid
						}
					}, {
						nickname: dbCmd.exists(true)
					}])).update({
			error_ti:dbCmd.push(tis)
		});
		return res
	}
	else if(state==='收藏')
	{
		let res=await db.collection('uni-id-users').where(dbCmd.and([{
						wx_openid: {
							"mp-weixin": openid
						}
					}, {
						nickname: dbCmd.exists(true)
					}])).update({
			star_ti:dbCmd.push(tis)
		});
		return res
	}
};
